package ferp.android.dialogs;

import android.content.Context;
import android.graphics.Color;
import android.os.Environment;
import android.view.View;
import android.widget.TextView;
import ferp.android.GUI;
import ferp.android.R;
import ferp.android.managers.DeckManager;

import java.io.File;
import java.util.List;

/**
 * User: olegs
 * Date: 19/01/2015 14:14
 */
public class DecksDialog extends RadioListViewDialog
{
  public DecksDialog(Context context, Listener listener, int requestCode)
  {
    super(context, R.layout.dialog_decks, listener, requestCode);

    TextView note1 = resolveNote(R.id.dlg_decks_footer_note1, GUI.Color.TITLE);
    note2 = resolveNote(R.id.dlg_decks_footer_note2, Color.WHITE);

    note1.setText(R.string.dialog_decks_note);
    note2.setSelected(true);
  }

  @Override
  public void set(String title, List<String> options, int selected)
  {
    super.set(title, options, selected);

    Context context = getContext();
    File folder = DeckManager.instance(context).folder();
    int color = Color.RED;
    String text;

    if (folder == null)
    {
      File esd = Environment.getExternalStorageDirectory();

      if (esd != null)
        text = esd.getAbsolutePath() + File.separator + "Android" + File.separator + "data" + File.separator + context.getPackageName() + File.separator + "files" + File.separator + "decks" + File.separator;
      else
        text = context.getString(R.string.error_external_storage);
    }
    else
    {
      text = folder.getAbsolutePath();

      if (folder.exists())
        color = Color.GREEN;
    }

    note2.setTextColor(color);
    note2.setText(text);
  }

  @Override
  protected int getFooterVisibility() {return View.VISIBLE;}

  private final TextView note2;

  private TextView resolveNote(int id, int color)
  {
    TextView tv = (TextView)findViewById(id);

    tv.setTypeface(GUI.Font.BOLD);
    tv.setTextColor(color);

    return tv;
  }
}
